﻿Public Class AuxFunctions

    'START OF JAWAD IDEA
    'Just an idea that may help you Joe
    'First, Here is a method that will convert a data set to a list (you can use and array too)
    'NOTE : row in this case is a row from the first table in the dataset
    '       row can have 1 column (studentID for example) than you cast the row of type object to a string/number using row.Field("fieldName") or row.item(index) methods
    '       if the row has more than on column (for example a complete student record from the student table, then you take each item from the objList returned and cast it to string/number then place it in an array

    Public Shared Function ToList(ByVal ds As DataSet, ByVal colIndex As Integer) As List(Of String)
        Dim objList As New List(Of String)
        For Each row As DataRow In ds.Tables(0).Rows
            objList.Add(row.Item(colIndex).ToString)
        Next
        Return objList ' the items of this list are strings. Each string is the data in the column at index colindex of the corresponding row
    End Function

    'Now, the following method looks for matching items of list1 in list2 (both converted from a dataset using above function) returns an array of the matching items
    '(for example, list1 can contain the list of courseIDs in a major requirement, list2 contains the student's course record)
    'returns nothing if no match found
    Private Function getRequirementMatches(ByVal list1 As List(Of String), ByVal list2 As List(Of String)) As ArrayList
        Dim arrListOfMatches As New ArrayList
        Try
            For Each item1 As String In list1
                For Each item2 As String In list2
                    If item1.ToLower = item2.ToLower Then
                        arrListOfMatches.Add(item1)
                    End If
                Next
            Next

        Catch e As Exception
            arrListOfMatches = Nothing
        End Try

        Return arrListOfMatches
    End Function

    'The following method looks in the getRequirementMatches' array returned above, for the combo's to satisfy a requirement
    ' I HAVE NO IDEA HOW TO DO THIS YET :) I

    'END OF JAWAD IDEA

End Class
